/*
 * elipse.c
 *
 *  Created on: 17/02/2013
 *      Author: alex
 */

#include "../headers/elipse.h"

long double IntElipse(long double Xe, long double Ye, long double Ze,
						long double Xd, long double Yd, long double Zd,
						long double Xf1, long double Yf1, long double Zf1,
						long double Xf2, long double Yf2, long double Zf2,
						long double A, long double B, long double C, long double D, long double L,
						objeto_t *objeto)
{
    long double Xi,Yi,Zi;
    long double t, distancia;

    // Averiguar la intersección con el plano
	t = -((A * Xe + B * Ye + C * Ze + D) / (A * Xd + B * Yd + C * Zd));

    Xi = Xe + t*Xd;
    Yi = Ye + t*Yd;
    Zi = Ze + t*Zd;

    distancia = sqrt(pow(Xf1-Xi,2)+pow(Yf1-Yi,2)+pow(Zf1-Zi,2)) +
                sqrt(pow(Xf2-Xi,2)+pow(Yf2-Yi,2)+pow(Zf2-Zi,2));

    if ((distancia <= L) && (Cortar(objeto,Xi,Yi,Zi) == 1))
        return t;
    else
        return -1.0;
}

long double* NormalElipse(long double N[3])
{
    long double *Normal;
    Normal = (long double*)malloc(3 * sizeof(long double));
  	Normal[0] = N[0];
  	Normal[1] = N[1];
  	Normal[2] = N[2];

  	return Normal;
}
